How do you get and use a Refresh Token for the Dropbox API (Python 3.x)
- Replace
<APP_KEY>
with your dropbox app key in the below Authorization URL
https://www.dropbox.com/oauth2/authorize?client_id=<APP_KEY>&token_access_type=offline&response_type=code
-
Complete the code flow on the Authorization URL. You will receive an AUTHORIZATION_CODE at the end.
-
Go to Postman and create a new POST request with below configuration
- Request URL- https://api.dropboxapi.com/oauth2/token
- Authorization
Type = Basic Auth
_Username_ = <APP_KEY>
_Password_ = <APP_SECRET>
(Refer this answer for cURL -u option)
- Body -> Select "x-www-form-urlencoded"
Key | Value |
---|---|
code | <AUTHORIZATION_CODE> |
grant_type | authorization_code |
- After you send the request, you will receive JSON payload containing refresh_token.
{
"access_token": "sl.****************",
"token_type": "bearer",
"expires_in": 14400,
"refresh_token": "*********************",
"scope": <SCOPES>,
"uid": "**********",
"account_id": "***********************"
}
- In your python application
import dropbox
dbx = dropbox.Dropbox(
app_key = <APP_KEY>,
app_secret = <APP_SECRET>,
oauth2_refresh_token = <REFRESH_TOKEN>
)